<!--
 * @Author: your name
 * @Date: 2021-09-16 10:52:01
 * @LastEditTime: 2021-09-16 17:25:21
 * @LastEditors: hucc
 * @Description: In User Settings Edit
 * @FilePath: \briup\6-jQuery\day05\10-A1.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>A1</title>
    <script>
        //A1---B1  发送和接收
        //A1 发送消息：win.postMessage()
        //B1  接收消息  window.onmessage=function(){}接收
        window.onload = function() {
            //获取按钮
            var btn = document.getElementsByTagName("button")[0];
            //获取发送按钮
            var sendBtn = document.getElementById("send");
            //给第一个按钮绑定事件
            btn.onclick = function() {
                    //打开B1窗口
                    win = window.open("./11-B1.html");
                }
                //给发送数据按钮绑定事件
            sendBtn.onclick = function() {
                var obj = {
                        name: "zs",
                        age: 12
                    }
                    //发送的消息 目标源:可写可不写，会默认显示
                win.postMessage(obj);
            }
        }
    </script>
</head>

<body>
    <button>打开B1窗口 </button>
    <button id="send">发送数据</button>
</body>

</html>
</html>